/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Period;

/**
 * <p>Project: jse2204 - Time1
 * <p>Powered by webrx On 2022-08-31 14:45:41
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Time1 {
    public static void main(String[] args) {
        //计算两个日期之间的天数
        var a = LocalDate.of(1999,3,5); //开始日期
        var b = LocalDate.now();//结束日期

        //toEpochDay() 返回当前日期的天数表达
        System.out.println(a.toEpochDay());
        System.out.println(b.toEpochDay());
        System.out.println(b.toEpochDay()-a.toEpochDay());


        var t1 = LocalDateTime.of(1999,3,5,0,0,0);
        var t2 = LocalDateTime.now();
        Duration d = Duration.between(t1,t2);
        System.out.println(d.toDays());
        System.out.println(d.toHours());


        LocalDate birthday = LocalDate.of(2002,8,6);
        Period p = Period.between(birthday,b);
        System.out.println(p.getYears());
        System.out.printf("李四出生日期：%tF，到%tF，年龄：%d岁。%n",birthday,b,p.getYears());




    }
}
